

ac.game:event '单位-合成装备'(function(_,unit,items,point)
    local player = unit.owner
    local list = {}
    for a=1,7 do
        list[a] = {}
    end
    for _,it in ipairs(items) do
        if it.item_class=='装备' and (it.owner==nil or it.owner_player==player) and it['无法合成']==nil then
            table.insert(list[it.item_level],it)
        end
    end
    
    for level=7,1,-1 do
        local group = list[level]
        local count = math.floor(#group/3)
        for a=1,count do
            for b=1,3 do
                local it = group[(a-1)*3+b]
                it:remove()
            end

            local name = ''
            if level==6 then
                name = '6级装备礼包'
            elseif level==7 then
                name = '7级装备礼包'
            else
                name = random_item_name(level+1)
            end
            local item = ac.item.create(name,point or unit:get_point())
            item.owner_player = player
            if point then
                point:add_effect([[Abilities\Spells\Items\AIem\AIemTarget.mdl]]):remove()
            else
                item:give(unit)
                unit:add_effect([[Abilities\Spells\Items\AIem\AIemTarget.mdl]], 'origin'):remove()
            end
            player:send_msg(('|cff00ff00装备合成:%s'):format(item:get_title()))
        end
    end
end)


ac.game:event '单位-即将获得物品'(function(_,unit,item)
    local max = 7
    local level = item.item_level or 1
    if unit:is_type('英雄') and level>6 then
        max = 6
        for _,it in ipairs(unit:get_items()) do
            if it.name==item.name and it~=item then
                return false,'6级以上装备同名只能携带一件'
            end
        end
    end
end)

